// pages/main/index/postDetail/popView/popView.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    //开启动画
    animation: {
      type: Boolean,
      value: true
    },
    //弹出类型  可选值，top: 顶部弹出层；bottom：底部弹出层；center：全屏弹出层
    type: {
      type: String,
      value: 'bottom'
    },
    maskClick: {
      type: Boolean,
      value: true
    },
    show: {
      type: Boolean,
      value: true,
      observer:function(newVal,oldVal,change){
        if (newVal) {
          this.open()
        } else {
          this.close()
        }
      }
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    ani: '',
    showPopup: false,
    
  },

  /**
   * 组件的方法列表
   */
  methods: {
    clearMovePass() {},
    clearTapPass() {},
    //打开
    open(){
      let that = this
      // console.log("打开弹窗")
      this.triggerEvent("change",{
        show: true
      })

      this.showPopup = true

      wx.nextTick(()=>{
        // setTimeout(()=>{
          this.ani = 'uni-' + this.properties.type
          // console.log("改变了")
          // console.log('刷新')
          that.setData({
            ani: this.ani,
            showPopup: this.showPopup
          })
        // },100)
      })

    },

    //关闭
    close(e){
      // console.log("关闭弹窗")
      const {type} = e.currentTarget.dataset
      // console.log(this.properties.maskClick)
      // console.log(type)
      if (!this.properties.maskClick || !type) return
      this.triggerEvent("change",{
        show: false
      })
      this.ani = ''
      wx.nextTick(()=>{
        // setTimeout(()=>{
          this.showPopup = false
          this.setData({
            ani: this.ani,
            showPopup: this.showPopup
          })
        // },300)
      })

      
    }
  }
})
